#define _CRT_SECURE_NO_WARNINGS  1


class Solution
{
public:
    int longestOnes(vector<int>& nums, int k)
    {
        int left = 0;
        int right = 0;
        int ret = 0;
        int count = 0;

        while (right < nums.size())
        {
            if (nums[right] == 0)
                count++;
            while (count > k)
            {
                if (nums[left++] == 0)
                    count--;
            }
            ret = max(ret, right - left + 1);
            right++;
        }
        return ret;
    }
};